﻿using System;
using System.Data;
using System.Windows.Forms;
using AMS.Inventory.PCClient.InventoryHelpClass;


namespace AMS.Inventory.PCClient
{
    public partial class LoginFrm : Form
    {
        public LoginFrm()
        {
            InitializeComponent();
        }

        SqlDb m_Db = new SqlDb();
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.None;
            var strCode = txtUserName.Text.Replace('\'', ' ').Trim();
            var strPassword = txtPassword.Text.Replace('\'', ' ').Trim();
            if (string.IsNullOrEmpty(strCode) || string.IsNullOrEmpty(strPassword))
            {
                MessageBox.Show("賬號,密碼都不能為空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
 
            //  strPassword = publ.MD5(strPassword);
            strPassword = publ.VitEnctyptString(strPassword);
 
  
            try
            {
                var strSql = "select * from Frame_User where Code='" + strCode + "' and Password='" + strPassword + "'";
                DataSet ds = m_Db.GetDataSet(strSql);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    LoginUser.UserCode = ds.Tables[0].Rows[0]["Code"].ToString();
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    MessageBox.Show("賬號或密碼錯誤！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
    }
}
